package com.taobao.verticalbannerview;

import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.ForegroundColorSpan;
import android.view.View;

import com.taobao.library.VerticalBannerView;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);


        List<Model01> datas01 = new ArrayList<>();
        datas01.add(new Model01("白日依山尽", "--->白日依山尽"));
        datas01.add(new Model01("黄河入海流", "--->黄河入海流"));
        datas01.add(new Model01("欲穷千里目", "--->欲穷千里目"));
        datas01.add(new Model01("更上一层楼", "--->更上一层楼"));

        final SampleAdapter01 adapter01 = new SampleAdapter01(datas01);
        final VerticalBannerView banner01 = (VerticalBannerView) findViewById(R.id.banner_01);
        banner01.setAdapter(adapter01);


        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
            }
        });

        findViewById(R.id.btn_start).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                banner01.start();
            }
        });

        findViewById(R.id.btn_stop).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                banner01.stop();
            }
        });

        findViewById(R.id.btn_update).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                List<Model01> newData = new ArrayList<>();
                newData.add(new Model01("锄禾日当午", "--->锄禾日当午"));
                newData.add(new Model01("汗滴禾下土", "--->汗滴禾下土"));
                newData.add(new Model01("谁知盘中餐", "--->谁知盘中餐"));
                newData.add(new Model01("粒粒皆辛苦", "--->粒粒皆辛苦"));
                adapter01.setData(newData);
            }
        });


        //-----------------------
        List<Model01> datas02 = new ArrayList<>();
        datas02.add(new Model01("Life was so beautiful", "--->Life was so beautiful,"));
        datas02.add(new Model01("From morning to evening", "--->From morning to evening"));
        datas02.add(new Model01("We enjoyed the road to school", "--->We enjoyed the road to school,"));
        datas02.add(new Model01("Birds chirped and Peace lingered", "--->Birds chirped and Peace lingered"));
        final SampleAdapter02 adapter02 = new SampleAdapter02(datas02);
        final VerticalBannerView banner02 = (VerticalBannerView) findViewById(R.id.banner_02);
        banner02.setAdapter(adapter02);
        banner02.start();

        //------------------------

        List<Model01> datas03 = new ArrayList<>();
        datas03.add(new Model01("Life is so insecure", "最新"));
        datas03.add(new Model01("From afternoon to night", "最火爆"));
        datas03.add(new Model01("We fear the road to school", "hot"));
        datas03.add(new Model01("There may be destructive bombs,Peace has demolished", "new"));
        final SampleAdapter03 adapter03 = new SampleAdapter03(datas03);
        final VerticalBannerView banner03 = (VerticalBannerView) findViewById(R.id.banner_03);
        banner03.setAdapter(adapter03);
        banner03.start();

        String string = "到南京时，有朋友约去游逛，勾留7了一日；第二日上午便须渡江到浦口，下午上车北去。父亲因为事忙，本已说定不送我，叫旅馆里一个熟识的茶房8陪我同去。他再三嘱咐茶房，甚是仔细。但他终于不放心，怕茶房不妥帖9；颇踌躇10了一会。其实我那年已二十岁，北京已来往过两三次，是没有什么要紧的了。他踌躇了一会，终于决定还是自己送我去。我再三劝他不必去；他只说：“不要紧，他们去不好！";
        SpannableString spannableString = new SpannableString(string);

        String highLight;

        highLight = "到南京时，有朋友约去游逛";
        int startIndex = string.indexOf(highLight);
        int endIndex = startIndex + highLight.length();
        spannableString.setSpan(new ForegroundColorSpan(getResources().getColor(android.R.color.holo_red_dark)),
                startIndex,
                endIndex,
                Spanned.SPAN_INCLUSIVE_INCLUSIVE);//高亮


        highLight = "第二日上午便须渡江到浦口，下午上车北去。";
        startIndex = string.indexOf(highLight);
        endIndex = startIndex + highLight.length();
        spannableString.setSpan(new ForegroundColorSpan(getResources().getColor(android.R.color.holo_orange_dark)),
                startIndex,
                endIndex,
                //Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);//高亮
                Spanned.SPAN_INCLUSIVE_INCLUSIVE);//高亮

        final VerticalBannerView banner04 = (VerticalBannerView) findViewById(R.id.banner_04);
        banner04.setData(spannableString);
        //banner04.start();
    }

}






















